package com.only.common.enums;

import java.util.Optional;

/**
 * @author only
 * @date 2023/6/15
 * @description
 */
public interface GeneralIdEnum extends IdBaseEnum {
    static <T extends GeneralIdEnum> Optional<T> create(Integer code, Class<T> enumType) {
        for (T value: enumType.getEnumConstants()) {
            if (value.getId().equals(code)) {
                return Optional.of(value);
            }
        }

        return Optional.empty();
    }

    public default GeneralEnumVO toEnumGeneralVO() {
        return new GeneralEnumVO(this);
    }
}
